package com.jerry.mingxing.ui.fashionrecommend;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.LabelBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/9/1.
 */
public class FashionRecommendLabelAdapter extends BaseAdapter {
    private List<LabelBean.ResponseBean.DataBean.ItemsBean> totallist;
    private Context context;
    private LayoutInflater inflater;

    public FashionRecommendLabelAdapter(List<LabelBean.ResponseBean.DataBean.ItemsBean> totallist, Context context) {
        this.context = context;
        this.totallist = totallist;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return totallist.size();
    }

    @Override
    public Object getItem(int position) {
        return totallist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.recommend_gridview_label, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.recommendGridviewSimp.setImageURI(Uri.parse(totallist.get(position).getComponent().getPicUrl()));
        viewHolder.recommendGridviewTv.setText(totallist.get(position).getComponent().getTitle());
        return convertView;
    }

    public void reloadData(List list) {

        totallist = list;
        notifyDataSetChanged();
    }

    static class ViewHolder {
        @Bind(R.id.recommend_gridview_simp)
        SimpleDraweeView recommendGridviewSimp;
        @Bind(R.id.recommend_gridview_tv)
        TextView recommendGridviewTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
